﻿Public Class topXProcessesControl
    Dim o As Integer = 0

    Private Sub topXProcessesControl_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim process As New Process
        Dim count As Integer = 0
        ListView1.Items.Clear()
        For Each process In process.GetProcesses(My.Computer.Name)
            On Error Resume Next
            ListView1.Items.Add(process.ProcessName)
            ListView1.Items(count).SubItems.Add(FormatNumber(Math.Round(process.PrivateMemorySize64 / 1024), 0))
            ListView1.Items(count).SubItems.Add(process.Responding)
            ListView1.Items(count).SubItems.Add(process.Id)
            count += 1
            If o = 0 Then
                If count = 10 Then Exit For
            End If

        Next
        If o = 0 Then ToolStripStatusLabel1.Text = "processes: 10 of " & process.GetProcesses.Length Else ToolStripStatusLabel1.Text = "processes: " & process.GetProcesses.Length
    End Sub

    Private Sub ToolStripButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton2.Click
        o = 1
        topXProcessesControl_Load(Nothing, Nothing)
    End Sub

    Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
        o = 0
        topXProcessesControl_Load(Nothing, Nothing)
    End Sub
End Class
